import vecc_lexer
import gramloader

from Lexer import *
from pars import *

def test1():
    automata = vecc_lexer.getVectorCAutomata()
    lexer = Lexer(automata, BufferedFileReader('grammar_test.code'))

    g = gramloader.loadGrammar('grammar.py')

    push_lexer = PushLexer(lexer)
    comment_strip_lexer = CommentFilterLexer(push_lexer)
    final_lexer = KeywordLexer(comment_strip_lexer, ['if', 'for', 'print', 'read', 'goto', 'label', 'while', 'return', 'operator', 'struct', 'typedef'])
    analyzer = SRAnalyzer(final_lexer, g.f, g.g)
    result = analyzer.run()
    print
    return result


if __name__ == '__main__':
    result = test1()
    print
    print 'Generated program:'
    for l in result:
        print l
